package demo;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import lib.OneMenuNoClickFilter;
import lib.StringEdit;
import lib.TwoMenuFilter;


import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.sun.xml.internal.txw2.Document;

public class demo2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String url = "http://www.sachgiamgia.vn/";
		String str1="/html/body/div/div[7]/div/div[2]/div/ul";
		str1= StringEdit.EditXpath(str1);
		String str2="/html/body/div/div[7]/div/div[2]/div/ul";
		str2= StringEdit.EditXpath(str2);
		String str3="/body/div/div[7]/div/div[2]/div/ul";
		str3 =StringEdit.EditXpath(str3);
		
		TwoMenuFilter filter = new TwoMenuFilter();
		filter.lay_noi_dung_web(url, str1, str2);
		
		List<String> name= filter.getTopicDic();
		List<String> link= filter.getLink();
		for(int i = 0; i< name.size();i++)
		{
			Writer out1;
			try {
				out1 = new BufferedWriter(new OutputStreamWriter(
						new FileOutputStream("E:\\giamgia.txt",true),"UTF-8"));
				try {
					out1.write(name.get(i));
					out1.write(System.getProperty( "line.separator" ));
					out1.write(System.getProperty( "line.separator" ));
					out1.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
					
		}
	}

}
